<template>
  <div>
    <div class="gva-form-box">
      <el-form :model="formData" ref="elFormRef" label-position="right" :rules="rule" label-width="80px">
        <el-form-item label="编号:" prop="number">
          <el-input v-model="formData.number" :clearable="true" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="制造序列号:" prop="manufacturing_serial_number">
          <el-input v-model="formData.manufacturing_serial_number" :clearable="true" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="排故日期:" prop="troubleshooting_date">
          <el-date-picker v-model="formData.troubleshooting_date" type="date" placeholder="选择日期" :clearable="true"></el-date-picker>
        </el-form-item>
        <el-form-item label="故障对应的工艺设计文件号:" prop="process_design_document_number">
          <el-input v-model="formData.process_design_document_number" :clearable="true" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="负责工艺员:" prop="responsible_craftman">
          <el-input v-model="formData.responsible_craftman" :clearable="true" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="故障描述:" prop="fault_description">
          <el-input v-model="formData.fault_description" :clearable="true" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="DISR号:" prop="dISR_number">
          <el-input v-model="formData.dISR_number" :clearable="true" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="序号1:" prop="serial_number1">
          <el-input v-model.number="formData.serial_number1" :clearable="true" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="操作描述1:" prop="operation_description1">
          <el-input v-model="formData.operation_description1" :clearable="true" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="是否需要质量检查1:" prop="is_quality_inspection_required1">
          <el-switch v-model="formData.is_quality_inspection_required1" active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" clearable ></el-switch>
        </el-form-item>
        <el-form-item label="序号2:" prop="serial_number2">
          <el-input v-model.number="formData.serial_number2" :clearable="true" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="操作描述2:" prop="operation_description2">
          <el-input v-model="formData.operation_description2" :clearable="true" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="是否需要质量测查2:" prop="is_quality_inspection_required2">
          <el-switch v-model="formData.is_quality_inspection_required2" active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" clearable ></el-switch>
        </el-form-item>
        <el-form-item label="序号3:" prop="serial_number3">
          <el-input v-model.number="formData.serial_number3" :clearable="true" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="操作描述3:" prop="operation_description3">
          <el-input v-model="formData.operation_description3" :clearable="true" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="是否需要质量检测3:" prop="is_quality_inspection_required3">
          <el-switch v-model="formData.is_quality_inspection_required3" active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" clearable ></el-switch>
        </el-form-item>
        <el-form-item label="序号4:" prop="serial_number4">
          <el-input v-model.number="formData.serial_number4" :clearable="true" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="操作描述4:" prop="operation_description4">
          <el-input v-model="formData.operation_description4" :clearable="true" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="是否需要质量检查4:" prop="is_quality_inspection_required4">
          <el-switch v-model="formData.is_quality_inspection_required4" active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" clearable ></el-switch>
        </el-form-item>
        <el-form-item label="序号5:" prop="serial_number5">
          <el-input v-model.number="formData.serial_number5" :clearable="true" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="操作描述5:" prop="operation_description5">
          <el-input v-model="formData.operation_description5" :clearable="true" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="是否需要质量检测5:" prop="is_quality_inspection_required5">
          <el-switch v-model="formData.is_quality_inspection_required5" active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" clearable ></el-switch>
        </el-form-item>
        <el-form-item label="ATA章节（一级）:" prop="ata_chapter_level1">
          <el-input v-model="formData.ata_chapter_level1" :clearable="true" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="ATA章节（二级）:" prop="ata_chapter_level2">
          <el-input v-model="formData.ata_chapter_level2" :clearable="true" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="纸质排故单上传:" prop="upload_troubleshooting_form">
          <el-input v-model="formData.upload_troubleshooting_form" :clearable="true" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="附件上传:" prop="upload_attachment">
          <el-input v-model="formData.upload_attachment" :clearable="true" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="结论:" prop="conclusion">
          <el-input v-model="formData.conclusion" :clearable="true" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="完成时间:" prop="complete_date">
          <el-date-picker v-model="formData.complete_date" type="date" placeholder="选择日期" :clearable="true"></el-date-picker>
        </el-form-item>
        <el-form-item label="是否通过:" prop="is_passed">
          <el-switch v-model="formData.is_passed" active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" clearable ></el-switch>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="save">保存</el-button>
          <el-button type="primary" @click="back">返回</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Case_struct_backup'
}
</script>

<script setup>
import {
  createCase_struct_backup,
  updateCase_struct_backup,
  findCase_struct_backup
} from '@/api/sysCaseLibrary_backup'

// 自动获取字典
import { getDictFunc } from '@/utils/format'
import { useRoute, useRouter } from "vue-router"
import { ElMessage } from 'element-plus'
import { ref, reactive } from 'vue'
const route = useRoute()
const router = useRouter()

const type = ref('')
const formData = ref({
            number: '',
            manufacturing_serial_number: '',
            troubleshooting_date: new Date(),
            process_design_document_number: '',
            responsible_craftman: '',
            fault_description: '',
            dISR_number: '',
            serial_number1: 0,
            operation_description1: '',
            is_quality_inspection_required1: false,
            serial_number2: 0,
            operation_description2: '',
            is_quality_inspection_required2: false,
            serial_number3: 0,
            operation_description3: '',
            is_quality_inspection_required3: false,
            serial_number4: 0,
            operation_description4: '',
            is_quality_inspection_required4: false,
            serial_number5: 0,
            operation_description5: '',
            is_quality_inspection_required5: false,
            ata_chapter_level1: '',
            ata_chapter_level2: '',
            upload_troubleshooting_form: '',
            upload_attachment: '',
            conclusion: '',
            complete_date: new Date(),
            is_passed: false,
        })
// 验证规则
const rule = reactive({
               manufacturing_serial_number : [{
                   required: true,
                   message: '',
                   trigger: ['input','blur'],
               }],
               troubleshooting_date : [{
                   required: true,
                   message: '',
                   trigger: ['input','blur'],
               }],
               process_design_document_number : [{
                   required: true,
                   message: '',
                   trigger: ['input','blur'],
               }],
               responsible_craftman : [{
                   required: true,
                   message: '',
                   trigger: ['input','blur'],
               }],
               fault_description : [{
                   required: true,
                   message: '',
                   trigger: ['input','blur'],
               }],
               ata_chapter_level1 : [{
                   required: true,
                   message: '',
                   trigger: ['input','blur'],
               }],
               ata_chapter_level2 : [{
                   required: true,
                   message: '',
                   trigger: ['input','blur'],
               }],
})

const elFormRef = ref()

// 初始化方法
const init = async () => {
 // 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
    if (route.query.id) {
      const res = await findCase_struct_backup({ ID: route.query.id })
      if (res.code === 0) {
        formData.value = res.data.recase_backup
        type.value = 'update'
      }
    } else {
      type.value = 'create'
    }
}

init()
// 保存按钮
const save = async() => {
      elFormRef.value?.validate( async (valid) => {
         if (!valid) return
            let res
           switch (type.value) {
             case 'create':
               res = await createCase_struct_backup(formData.value)
               break
             case 'update':
               res = await updateCase_struct_backup(formData.value)
               break
             default:
               res = await createCase_struct_backup(formData.value)
               break
           }
           if (res.code === 0) {
             ElMessage({
               type: 'success',
               message: '创建/更改成功'
             })
           }
       })
}

// 返回按钮
const back = () => {
    router.go(-1)
}

</script>

<style>
</style>
